package biz.datalk.industrialland.admin.modules.online.dynform.controller;

import biz.datalk.industrialland.admin.modules.online.dynform.pojo.dto.DynformButtonDTO;
import biz.datalk.industrialland.admin.modules.online.dynform.service.IDynformButtonService;
import biz.datalk.industrialland.common.encrypt.annotation.RSAES;
import biz.datalk.industrialland.common.result.UnifyResult;
import biz.datalk.industrialland.common.validated.Delete;
import biz.datalk.industrialland.common.validated.Detail;
import biz.datalk.industrialland.common.validated.Insert;
import biz.datalk.industrialland.common.validated.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tarofang@163.com
 * @date 2019-12-17
 */
@RestController
@RequestMapping("/dynform/button")
public class DynformButtonController {

    private final IDynformButtonService dynformButtonService;

    @Autowired
    public DynformButtonController(IDynformButtonService dynformButtonService) {
        this.dynformButtonService = dynformButtonService;
    }

    @RSAES
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    // @Json(type = DynformHeadDTO.class, include = "",filter = "password,salt,createTime,updateTime")
    public UnifyResult list(@RequestBody DynformButtonDTO dynformButtonDTO) {
        return dynformButtonService.list(dynformButtonDTO);
    }

    @RSAES
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UnifyResult add(@RequestBody @Validated({Insert.class}) DynformButtonDTO dynformButtonDTO) {
        return dynformButtonService.add(dynformButtonDTO);
    }

    @RSAES
    @PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UnifyResult edit(@RequestBody @Validated({Update.class}) DynformButtonDTO dynformButtonDTO) {
        return dynformButtonService.edit(dynformButtonDTO);
    }

    @RSAES
    @PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UnifyResult delete(@RequestBody @Validated({Delete.class}) DynformButtonDTO dynformButtonDTO) {
        return dynformButtonService.delete(dynformButtonDTO);
    }

    @RSAES
    @PostMapping(value = "/detail", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public UnifyResult detail(@RequestBody @Validated({Detail.class}) DynformButtonDTO dynformButtonDTO) {
        return dynformButtonService.detail(dynformButtonDTO);
    }



}
